package com.bocom.hairy.crab.base.common;

import lombok.Data;

import java.io.Serializable;

/**
 * @ClassName com.bocom.hairy.crab.base.common.R <br/>
 * @Description: 统一返回结果类       <br/>
 * @Author jiangshikun             <br/>
 * @Date 2025/9/3 下午1:50         <br/>
 * @Version V1.0
 * ----------------------------------------
 * （^-^）心即理，知行合--致良知 （^-^）
 * 邮 箱:duzhuai@live.cn
 * 地 址：北京市海淀区永澄北路2号
 **/
@Data
public class ResultDate<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    private int code;
    private String msg;
    private T data;
    private long timestamp;

    public ResultDate() {
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> ResultDate<T> ok() {
        return ok(null);
    }

    public static <T> ResultDate<T> ok(T data) {
        ResultDate<T> result = new ResultDate<>();
        result.setCode(200);
        result.setMsg("成功");
        result.setData(data);
        return result;
    }

    public static <T> ResultDate<T> error(String msg) {
        return error(500, msg);
    }

    public static <T> ResultDate<T> error(int code, String msg) {
        ResultDate<T> result = new ResultDate<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
